package com.jeesite.modules.dataScreen.service;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson2.JSONObject;
import com.jeesite.modules.dataScreen.web.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static com.jeesite.modules.dataScreen.web.vo.IndustryIndexFun.fun;

@Service
public class NavService {
    //公路管理
    private static final String[] JCSS_GLGL = new String[]{
            "路网实时车流量", "当前普通国省道阻断事件数", "全市“十四五”规划高速公路通车里程完成率", "全市当年乡镇通三级及以上公路占比",
            "全市当年村民小组通硬化路个数占比", "高速公路建设投资完成率", "普通国省道完成投资比例", "农村公路完成投资比例"
    };
    //港航管理
//    private static final String[] JCSS_GHGL = new String[]{
//            "船舶水污染物接收转运率-船舶垃圾","船舶水污染物接收转运率-生活污水","船舶水污染物接收转运率-含油污水",
//            "航标维护正常率-一级","航标维护正常率-二级", "航标维护正常率-三级"};
    private static final String[] JCSS_GHGL = new String[]{"高等级航道占比", "航标维护正常率"};
    //铁路管理
    private static final String[] JCSS_TLGL = new String[]{
            "当年铁路重点工程项目里程", "高速铁路里程", "普速铁路里程",
            "当年累计完成投资率", "去年铁路路网密度", "当年铁路重点工程项目总投资"};
    //民航管理
    private static final String[] JCSS_MHGL = new String[]{
            "全市运输机场跑道总条数", "江北机场跑道条数", "黔江机场跑道条数", "仙女山机场跑道条数", "万州机场跑道条数", "巫山机场跑道条数",
            "全市运输机场旅客吞吐能力", "全市运输机场货邮吞吐能力"};
    //邮政管理
    private static final String[] JCSS_YZGL = new String[]{
            "邮政普遍服务营业场所名录", "重庆市许可快递企业", "邮政行业寄递业务量", "快递业务量", "邮政网点覆盖率"};
    //铁路总里程
    private static final String[] TLZLC = new String[]{
            "高速铁路里程", "普速铁路里程"};
    //全市运输机场跑道总条数
    private static final String[] JCPDZTS = new String[]{
            "江北机场跑道条数", "黔江机场跑道条数", "仙女山机场跑道条数", "万州机场跑道条数", "巫山机场跑道条数"};
    @Autowired
    private IndustryIndexService industryIndexService;

    public CockpitVO cockpitData() {
        CockpitVO cockpitVO = new CockpitVO();
        industryIndexService.assembly(cockpitVO, false, CollUtil.toList(
                fun("高速公路技术状况指数(MQI)优良路率", CockpitVO::getGsgljszkzsMQIylll),
                fun("高速公路救援车辆30分钟到达率", CockpitVO::getGsgljycl30fzddl),
                fun("航标维护正常率", CockpitVO::getHbwhzcl),
                fun("航标维护正常率-一级", CockpitVO::getHbwhzclyj),
                fun("航标维护正常率-二级", CockpitVO::getHbwhzclej),
                fun("航标维护正常率-三级", CockpitVO::getHbwhzclsj),
                fun("危险货物港口作业量", CockpitVO::getWxhwgkzyl),
                fun("公路总里程", CockpitVO::getGlzlc),
                fun("重大桥梁实时监测健康率", CockpitVO::getZdqlssjcjkl),
                fun("普通国省道公路技术状况指数(MQI)优良路率", CockpitVO::getPtgsdgljszkzsMQIylll),

                fun("公路货运量占综合货运量比重", CockpitVO::getGlhyzzhhylbz),
                fun("道路货运量", CockpitVO::getDlhyl),
                fun("轨道列车正点率", CockpitVO::getGdlczdl)
        ));

        industryIndexService.assembly(cockpitVO, true, CollUtil.toList(
                fun("全市实时道路危货运输驾驶员健康度", CockpitVO::getQsssdlwhysjsyjkd),
                fun("全市实时道路危货运输车辆健康度", CockpitVO::getQsssdlwhyscljkd),
                fun("全市实时\"货车超限违法行为溯源\"多跨事件办结率", CockpitVO::getQssshccxwfxwsydksjbjl),
                fun("全市实时普通国省干线公路货车超限率", CockpitVO::getQsssptgsgxglhccxl),

                fun("轨道线网客流总量", CockpitVO::getGdxwklzl),
                fun("轨道列车正点率", CockpitVO::getGdlczdl)
        ));
        return cockpitVO;

    }

    public JSONObject trafficMainKPIClick() {

        String[] str1 = new String[]{"高速公路道路优良率","高速公路道路畅通率","高速公路公众出行满意度","高速公路救援车辆30分钟到达率",
                "高速公路服务区充电设施覆盖率","普通国省道阻断事件抢通率"};
        String[] str2  =new String[]{"枢纽机场近机位靠桥率80%以上","民航当年在建项目投资完成率","村级寄递物流综合服务站行政村覆盖率",
                "码头岸电设施\"十四五\"建设任务完成率","城市公共交通机动化出行分担率"};
        String[] str3  =new String[]{"公交轨道一体化换乘50米覆盖率","城市轨道交通客运分担率",
                "全市所有行政村通客车率","出租汽车纯电动率","机动车维修评价满意率","全市实时道路危货运输驾驶员健康度"};
        String[] str4 = new String[]{"全市实时道路危货运输车辆健康度","全市实时道路危货运输企业健康度", "全市当前道路危货运输安全隐患解除率",
                "当年道路危货运输人,车,企安全风险预警覆盖率", "危险货物运输电子运单企业覆盖率","行政执法案卷评查合格率"};
        String[] str5 = new String[]{"执法案件办理流程数字化率","较大及以上事件报送率","邮政项目计划投资","铁路营业里程",
                "当年铁路重点工程项目计划投资","水运项目计划投资"};
        String[] str6 = new String[]{"民航项目计划投资","综合交通计划投资","公路项目计划投资"};

        Map<String, IndustryIndexVo> dataMap = industryIndexService.getRealtime(str1,str2,str3,str4,str5,str6);
        Map<String, IndustryIndexVo> unRealtime = industryIndexService.getUnRealtime(str1,str2,str3,str4,str5,str6);
        dataMap.putAll(unRealtime);

        List<IndustryIndexVo> list1 = industryIndexService.getList(dataMap, IndustryIndexVo.consumerColor(), str1);
        List<IndustryIndexVo> list2 = industryIndexService.getList(dataMap, IndustryIndexVo.consumerColor(), str2);
        List<IndustryIndexVo> list3 = industryIndexService.getList(dataMap, IndustryIndexVo.consumerColor(), str3);
        List<IndustryIndexVo> list4 = industryIndexService.getList(dataMap, IndustryIndexVo.consumerColor(), str4);
        List<IndustryIndexVo> list5 = industryIndexService.getList(dataMap, IndustryIndexVo.consumerColor(), str5);
        List<IndustryIndexVo> list6 = industryIndexService.getList(dataMap, IndustryIndexVo.consumerColor(), str6);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("pageOne", list1);
        jsonObject.put("pageTwo", list2);
        jsonObject.put("pageThree", list3);
        jsonObject.put("pageFour", list4);
        jsonObject.put("pageFive", list5);
        jsonObject.put("pageSix", list6);
        return jsonObject;
    }

    public InfrastructureVO infrastructure() {
        InfrastructureVO result = new InfrastructureVO();
        Map<String, IndustryIndexVo> realtime = industryIndexService.getRealtime(JCSS_GLGL, JCSS_GHGL, JCSS_TLGL, JCSS_YZGL);
        Map<String, IndustryIndexVo> unRealtime = industryIndexService.getUnRealtime(JCSS_GLGL, JCSS_GHGL, JCSS_TLGL, JCSS_YZGL);
        realtime.putAll(unRealtime);

        result.setGlgl(industryIndexService.getList(realtime, JCSS_GLGL));
        result.setGhgl(industryIndexService.getList(realtime, JCSS_GHGL));
        result.setTlgl(industryIndexService.getList(realtime, JCSS_TLGL));
//        result.setMhgl(industryIndexService.getList(realtime, JCSS_MHGL));
        result.setYzgl(industryIndexService.getList(realtime, JCSS_YZGL));

//        IndustryIndexVo industryIndexVo = new IndustryIndexVo();
//        List<IndustryIndexVo> tlzlc = industryIndexService.getList(realtime, TLZLC);
//        BigDecimal tlzlcR = IndustryIndexVo.addAll(tlzlc);
//        industryIndexVo = new IndustryIndexVo("铁路总里程",tlzlcR.toString(),tlzlc.get(0).getUnit());
//        result.getTlgl().set(0,industryIndexVo);

//        List<IndustryIndexVo> jcpdzts = industryIndexService.getList(realtime, JCPDZTS);
//        BigDecimal jcpdztsR = IndustryIndexVo.addAll(jcpdzts);
//        industryIndexVo = new IndustryIndexVo("全市运输机场跑道总条数",jcpdztsR.toString(),jcpdzts.get(0).getUnit());
//        result.getMhgl().set(0,industryIndexVo);
        return result;

    }

    public List<IndustryIndexVo> trafficMainKPI() {
//        TrafficMainVo trafficMainVo = new TrafficMainVo(new IndustryIndexVo(),new IndustryIndexVo(),new IndustryIndexVo(),new IndustryIndexVo());
//        List<IndustryIndexFun<TrafficMainVo>> indexFuns = CollUtil.toList(
//                fun("高速铁路面积密度", TrafficMainVo::getGstlmjmd),
//                fun("高速公路面积密度", TrafficMainVo::getGsglmjmd),
//                fun("干线公路技术状况(MQI)优良路率", TrafficMainVo::getGxgljszkMQIylll),
//                fun("城市公共交通机动化出行分担率", TrafficMainVo::getCsggjtjdhcxfdl)
//        );
//        industryIndexService.assembly(trafficMainVo, false, indexFuns, IndustryIndexVo.consumerColor());
//        return trafficMainVo;

        String[] strings = new String[]{"高速铁路面积密度", "高速公路面积密度","干线公路技术状况(MQI)优良路率","城市公共交通机动化出行分担率"};
        Map<String, IndustryIndexVo> dataMap = industryIndexService.getUnRealtime(strings);
        return industryIndexService.getList(dataMap,IndustryIndexVo.consumerColor(),strings);
    }
}
